package com.pfzy.lib.common.http;

import android.app.Activity;
import android.app.Dialog;

import com.pfzy.lib.common.http.util.HttpUtils;
import com.pfzy.lib.net.BaseEntity;
import com.pfzy.lib.net.subscriber.DialogSubscriber;

import io.reactivex.disposables.Disposable;

public abstract class CCCXDialogSubscriber<T> extends DialogSubscriber<T> {
    boolean mShowError;

    @Override
    public void onSubscribe(Disposable d){
        try {
            super.onSubscribe(d);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onFinish() {
        try {
            super.onFinish();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public CCCXDialogSubscriber(Activity activity) {
        super(activity);
    }

    public CCCXDialogSubscriber(Dialog dialog) {
        super(dialog);
    }

    public CCCXDialogSubscriber(Activity activity, boolean showErrorToast) {
        super(activity, showErrorToast);
        this.mShowError = showErrorToast;
    }

    public CCCXDialogSubscriber(Dialog dialog, boolean showErrorToast) {
        super(dialog, showErrorToast);
        this.mShowError = showErrorToast;
    }

    @Override
    public boolean onBizError(BaseEntity baseEntity) {
        return ErrorCodeHandler.handle(baseEntity);
    }

    @Override
    public void onFailed(int code, String message) {
        HttpUtils.onFail(this.mShowError, code, message);
    }
}
